/* CASL assembly language head file
 *
 * including assemble.c execute.c
 *           instructions.c memory.c
 *
 * written by taiqwu<taiqwu@yeah.net> on March 6, 2002
 */
#ifndef _CASL_H_
#define _CASL_H_

#ifndef WORD
/* if int is 32bit & short is 16bit */
#define WORD short
#define UWORD unsigned short
#define DWORD int
#endif /* WORD */

typedef enum {NONE=0,REMARK=0,MACHINE=1,MACRO=1,PSEUDO=2} SENTENCE_TYPE;

typedef struct _LABEL
{
  char *name;
  UWORD address;
  struct _LABEL *next;
} LABEL;

typedef enum {VAR_BIN,VAR_DEC,VAR_HEX,VAR_LABEL,VAR_STRING} VAR_TYPE;

typedef struct _VARIABLE
{
  char *name;
  UWORD address;
  int length;
  VAR_TYPE type;
  struct _VARIABLE *next;
} VARIABLE;

typedef struct
{
  char * string;		/* Source Line String */
  char * operand;		/* operand start of source line string */
  UWORD op;
  LABEL *label;			/* label if have, NULL means no label */
  UWORD address,length;		/* address & length of code */
  SENTENCE_TYPE type;
} SENTENCE;

typedef struct			/* op GR[GRno],ADR,GR[XRno] */
{
  UWORD : 5;
  UWORD op: 5;
  UWORD GRno: 3;
  UWORD XRno: 3;
  UWORD ADR: 16;
} CODE;

typedef enum {GR_E=1,GR,E,BLANK,ALABEL_NLABEL} OPERAND_TYPE;

typedef struct			/* Machine(Comet) & Macro Operation Table */
{
  char *name;
  void (* execute)(WORD,WORD,WORD);
  int length;
  OPERAND_TYPE type;
} MOT;

typedef struct			/* Pseudo Operation Table */
{  char *name;
  int (* length)(char *),	/* get the length of instruction */
    (* assemble)(UWORD , int);	/* do pseudo when assemble, parameter:
				   (address,sentence line) */
} POT;

typedef struct
{
  WORD GR[5], PC, FR;
} REGISTER;

#define MO_NUM 27	/* Machine(Comet)&Macro Operation number (with ZERO at the begin) */
#define PO_NUM 4	/* Pseudo Operation number */

#define MEMORY_SIZE 0x10000
#define WORD_PER_LINE 0x4	/* how many words in a line when display memory */

extern REGISTER reg,initreg;
extern MOT mot[];
extern POT pot[];
extern SENTENCE *sentences;
extern LABEL *labels;
extern VARIABLE *vars;
extern int SentenceNum;

extern UWORD end_PC;		/* the end of PC, is also the end/length of binary program */

#endif /* _CASL_H_ */
